//
//  MineFootViewModel.swift
//  HLSwiftWork
//
//  Created by hulinhu on 2018/6/13.
//  Copyright © 2018年 hulinhu. All rights reserved.
//

import UIKit
import Alamofire

//逃逸闭包:当函数执行结束后,才去调用函数内部的闭包,叫做逃逸闭包
//非逃逸闭包:当函数执行过程中,执行的函数内部的闭包,叫做非逃逸闭包 @noescape

class MineFootViewModel {
    
    class func loadMineFooterData(_ finishedBlock: @escaping (_ dataArray: [MineFootModel])->()){
        
        let urlString = "http://api.budejie.com/api/api_open.php"
        let parameter = [ "a": "square","c": "topic",]
        
        Alamofire.request(urlString, method: .get, parameters: parameter).responseJSON { (respond) in
            guard let dic = respond.result.value as? [String: Any]  else{
                return
            }
            guard let datas = dic["square_list"] as? [[String: Any]] else {
                return
            }
            NSLog("  输出数据 ---- %@", datas)
            // 数据绑定 加载
            var meFootViewModels = [MineFootModel]()
            for dic in datas {
                let model = MineFootModel(dic)
                meFootViewModels.append(model)
            }
            finishedBlock(meFootViewModels)
        }
    }
    
}
